package org.example.helloworld.controller;

import org.example.helloworld.entity.User;
import org.springframework.web.bind.annotation.*;

@RestController
public class ParamsController {
    @RequestMapping(value = "/getTest1", method = RequestMethod.GET)
    public String getTest1() {
        return "Get请求";
    }

    @RequestMapping(value = "/getTest2", method = RequestMethod.GET)
    public String getTest2(String nickname,String phone) {
        System.out.println("nickname: "+nickname);
        System.out.println("phone: "+phone);
        return "Get请求";
    }

    @RequestMapping(value = "/getTest3", method = RequestMethod.GET)
//    public String getTest3(String name) {
//    将前端传递的参数nickname，改为name
    public String getTest3(@RequestParam("nickname") String name) {
        System.out.println("nickname: "+name);
        return "Get请求";
    }

    @RequestMapping(value = "/postTest1", method = RequestMethod.POST)
    public String postTest1(String nickname,String phone) {
        return "Post请求";
    }

    @RequestMapping(value = "/postTest2", method = RequestMethod.POST)
    public String postTest2(String username,String password) {
        System.out.println("username: "+username);
        System.out.println("password: "+password);
        return "Post请求";
    }

    @RequestMapping(value = "/postTest3", method = RequestMethod.POST)
    public String postTest3(User user) {
        System.out.println("user: "+user);
        return "Post请求";
    }

    @RequestMapping(value = "/postTest4", method = RequestMethod.POST)
//    RequestBody 数据使用的json
    public String postTest4(@RequestBody User user) {
        System.out.println("user: "+user);
        return "Post请求";
    }

    @GetMapping("/test/**")
    public String test() {
        return "通配符请求";
    }

}
